home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / PCHDT_E3.CAB / HCsrc_04.js < prev    next >
Encoding:
JavaScript  |  2003-02-21  |  8.7 KB  |  360 lines

  1. //
  2. // Copyright (c) 2001 Microsoft Corporation
  3. //
  4.  
  5. function Server_Generate()
  6. {
  7.     try
  8.     {
  9.         Server_PrepareNode( idTaxo, idTaxo, null, null );
  10.         Server_Build( idTaxo );
  11.     }
  12.     catch(e)
  13.     {
  14.     }
  15.  
  16.     idTopLevelTable.style.display = "";
  17. }
  18.  
  19.  
  20. function Server_Build( node )
  21. {
  22.     var qrc    = pchealth.Database.LookupNodesAndTopics( node.HC_PARENT ? node.HC_PAYLOAD.FullPath : "", true );
  23.     var html   = "";
  24.     var fLarge = (node.HC_PARENT != null);
  25.  
  26.     if(qrc.Count == 0)
  27.     {
  28.         node.HC_FLYOUT   = false;
  29.         node.HC_SUBNODES = null;
  30.     }
  31.  
  32.     for(var e = new Enumerator( qrc ); !e.atEnd(); e.moveNext())
  33.     {
  34.         var qr      = e.item();
  35.         var fFlyout = (qr.Entry && qr.Subsite == false);
  36.  
  37.         html += Server_CreateNode( qr.FullPath, qr.Title, qr.Description, fFlyout, fLarge );
  38.     }
  39.  
  40.     if(node.HC_PARENT)
  41.     {
  42.         node.HC_CHILDREN = Server_CreateFlyout( node, html );
  43.     }
  44.     else
  45.     {
  46.         node.innerHTML = html;
  47.  
  48.         node.HC_CHILDREN = node.firstChild;
  49.     }
  50.  
  51.     Server_LocateNodes( node, qrc );
  52. }
  53.  
  54. function Server_CreateNode( node, title, description, fFlyout, fLarge )
  55. {
  56.     var html;
  57.  
  58.     node        = pchealth.TextHelpers.QuoteEscape( node        );
  59.     title       = pchealth.TextHelpers.HTMLEscape ( title       );
  60.     description = pchealth.TextHelpers.QuoteEscape( description );
  61.  
  62.     html =  "<SPAN tabindex=-1 class='Taxo-Block' HC_NODE=\"" + node + "\" title=\"" + description + "\">";
  63.     html += "<TABLE" + (fLarge ? " width=100%" : "" ) + " border=0 cellpadding=0 cellspacing=0>";
  64.     html += "<TR class=Taxo-Cell>";
  65.     html += "<TD VALIGN='top' class='sys-font-body-bold Taxo-Bullet'><LI></TD><TD class='sys-font-body-bold Taxo-Title'>";
  66.  
  67.  
  68.     if(fFlyout)
  69.     {
  70.         var arrow = (window.document.documentElement.dir == "rtl") ? "3" : "4";
  71.  
  72.         html += "<SPAN ID=_IDFOCUS TABINDEX=100>" + title + " <SPAN style='font-family: marlett'>" + arrow + "</SPAN></SPAN>";
  73.     }
  74.     else
  75.     {
  76.         html += "<A class='Taxo-Title sys-homepage-color' ID=_IDFOCUS TABINDEX=100 HREF='hcp://services/subsite?node=" + node + "'>" + title + "</A>";
  77.     }
  78.  
  79.  
  80.     html += "</TD>";
  81.     html += "<TD style='display:none; width: 0px'>";
  82.     html += "</TD>";
  83.     html += "</TR>";
  84.     html += "</TABLE>";
  85.     html += "</SPAN>";
  86.  
  87.     return html;
  88. }
  89.  
  90. function Server_CreateFlyout( node, nodes )
  91. {
  92.     var tbl  = node.firstChild;
  93.     var row  = tbl.rows(0);
  94.     var cell = row.cells(2);
  95.  
  96.     var html = "";
  97.  
  98.     html += "<DIV class='sys-background-strong sys-toppane-color-border' style='width: 10em; position:absolute; z-index: 1; margin: 0px; border: 1pt solid'>";
  99.     html += nodes;
  100.     html += "</DIV>";
  101.  
  102.     node.HC_ATTACHFLYOUT = cell;
  103.  
  104.     cell.innerHTML = html;
  105.  
  106.     return cell.firstChild.firstChild;
  107. }
  108.  
  109. function Server_PrepareNode( elem, root, parent, qr )
  110. {
  111.     elem.HC_PARENT       = parent;
  112.     elem.HC_ROOT         = root;
  113.     elem.HC_PAYLOAD      = qr;
  114.     elem.HC_SUBNODES     = null;
  115.     elem.HC_CHILDREN     = null;
  116.     elem.HC_ATTACHFLYOUT = null;
  117.     elem.HC_HIGHLIGHTED  = 0;
  118.  
  119.     if(!root.HC_COLL)
  120.     {
  121.         root.HC_COLL     = [];
  122.         root.HC_CHAIN    = [];
  123.         root.HC_SELECTED = null;
  124.         root.HC_PENDING  = false;
  125.     }
  126.     root.HC_COLL[elem.uniqueID] = elem;
  127.  
  128.     if(qr)
  129.     {
  130.         elem.HC_FLYOUT = (qr.Entry && qr.Subsite == false);
  131.  
  132.         elem.onclick       = node_Server_click;
  133.         elem.oncontextmenu = node_Server_contextmenu;
  134.         elem.onmouseover   = node_Server_over;
  135.         elem.onmouseout    = node_Server_out;
  136.  
  137.         if(elem.all._IDFOCUS)
  138.         {
  139.             elem.all._IDFOCUS.onfocus = node_Server_over;
  140.             elem.all._IDFOCUS.onblur  = node_Server_out;
  141.         }
  142.     }
  143.     else
  144.     {
  145.         elem.HC_FLYOUT = true;
  146.     }
  147. }
  148.  
  149. function Server_LocateNodes( node, qrc )
  150. {
  151.     var obj = node.HC_CHILDREN;
  152.     var e   = new Enumerator( qrc );
  153.  
  154.     var array = [];
  155.     var first = null;
  156.     var last  = null;
  157.     while(obj && !e.atEnd())
  158.     {
  159.         if(!first) first = obj;
  160.  
  161.         Server_PrepareNode( obj, node.HC_ROOT, node, e.item() ); e.moveNext();
  162.  
  163.         array[array.length] = obj;
  164.  
  165.         obj.HC_POSITION = node.HC_PARENT ? "middle" : "root";
  166.  
  167.         last = obj;
  168.  
  169.         obj = obj.nextSibling;
  170.     }
  171.  
  172.     if(array.length)
  173.     {
  174.         node.HC_SUBNODES = array;
  175.  
  176.         if(node.HC_PARENT)
  177.         {
  178.             if(first == last) // only one node
  179.             {
  180.                 first.HC_POSITION = "single";
  181.             }
  182.             else
  183.             {
  184.                 first.HC_POSITION = "first";
  185.                 last .HC_POSITION = "last";
  186.             }
  187.         }
  188.     }
  189. }
  190.  
  191. function node_Server_find( node )
  192. {
  193.     while(node && !node.HC_PAYLOAD) node = node.parentElement;
  194.     return node;
  195. }
  196.  
  197. function node_Server_click()
  198. {
  199.     var node = node_Server_find( event.srcElement ); if(!node) return;
  200.  
  201.     Common_CancelEvent();
  202.  
  203.     if(node.HC_FLYOUT) return;
  204.  
  205.     try
  206.     {
  207.         var qr = node.HC_PAYLOAD;
  208.  
  209.         if(qr)
  210.         {
  211.             if(qr.Entry)
  212.             {
  213.                 pchealth.HelpSession.ChangeContext( "SubSite", qr.FullPath, qr.TopicURL );
  214.             }
  215.             else
  216.             {
  217.                 window.navigate( qr.TopicURL );
  218.             }
  219.         }
  220.     }
  221.     catch(e)
  222.     {
  223.     }
  224. }
  225.  
  226. function node_Server_contextmenu()
  227. {
  228.     var node = node_Server_find( event.srcElement ); if(!node) return;
  229.  
  230.     Common_CancelEvent();
  231.  
  232.     try
  233.     {
  234.         var qr = node.HC_PAYLOAD;
  235.  
  236.         if(qr)
  237.         {
  238.             pchealth.UI_NavBar.content.parentWindow.DoCommonContextMenu( -1, "subsite", qr );
  239.         }
  240.     }
  241.     catch(e)
  242.     {
  243.     }
  244. }
  245.  
  246. function node_Server_over()
  247. {
  248.     var node = node_Server_find( event.srcElement ); if(!node) return;
  249.  
  250.     {
  251.         var root = node.HC_ROOT;
  252.         var top  = node;
  253.         var sel  = [];
  254.         var i;
  255.  
  256.         if(root.HC_SELECTED == node)
  257.         {
  258.             root.HC_PENDING  = false;
  259.             return;
  260.         }
  261.  
  262.         while(top.HC_PARENT)
  263.         {
  264.             sel[top.uniqueID] = 1;
  265.  
  266.             top = top.HC_PARENT;
  267.         }
  268.  
  269.         for(i in root.HC_CHAIN)
  270.         {
  271.             if(!sel[i])
  272.             {
  273.                 node_Server_out_final( root.HC_COLL[i] );
  274.             }
  275.         }
  276.  
  277.         root.HC_CHAIN    = sel;
  278.         root.HC_SELECTED = node;
  279.         root.HC_PENDING  = false;
  280.     }
  281.  
  282.     if(node.HC_FLYOUT && !node.HC_SUBNODES)
  283.     {
  284.         Server_Build( node );
  285.     }
  286.  
  287.     switch(node.HC_POSITION)
  288.     {
  289.     case "root"  : node.className = "Taxo-Block sys-background-strong sys-toppane-color-border Taxo-Block-Highlight"       ; break;
  290.     case "single": node.className = "Taxo-Block sys-background-strong sys-toppane-color-border Taxo-Block-Highlight-Single"; break;
  291.     case "first" : node.className = "Taxo-Block sys-background-strong sys-toppane-color-border Taxo-Block-Highlight-First" ; break;
  292.     case "middle": node.className = "Taxo-Block sys-background-strong sys-toppane-color-border Taxo-Block-Highlight-Middle"; break;
  293.     case "last"  : node.className = "Taxo-Block sys-background-strong sys-toppane-color-border Taxo-Block-Highlight-Last"  ; break;
  294.     }
  295.  
  296.     var cell = node.HC_ATTACHFLYOUT;
  297.     if(cell && cell.style.display == "none")
  298.     {
  299.         cell.style.display = "";
  300.  
  301.         var div  = cell.firstChild;
  302.         var left = Common_GetLeftPosition( cell, true ) + cell.offsetWidth - 1;
  303.         var top  = Common_GetTopPosition ( cell, true ) - 1;
  304.         var room;
  305.  
  306.         room = document.body.clientHeight - (top - document.body.scrollTop);
  307.  
  308.         if(room < div.offsetHeight)
  309.         {
  310.             top += room - div.offsetHeight; if(top < 0) top = 0;
  311.         }
  312.  
  313.         if(window.document.documentElement.dir == "rtl")
  314.         {
  315.             div.style.right = document.body.clientWidth - left;
  316.         }
  317.         else
  318.         {
  319.             div.style.left = left;
  320.         }
  321.  
  322.         div.style.top  = top;
  323.     }
  324. }
  325.  
  326. function node_Server_out()
  327. {
  328.     var node = node_Server_find( event.srcElement ); if(!node) return;
  329.     var root = node.HC_ROOT;
  330.  
  331.     root.HC_PENDING = true;
  332.     window.setTimeout( "node_Server_out_timeout( " + root.uniqueID + " )", 100 );
  333. }
  334.  
  335. function node_Server_out_timeout( root )
  336. {
  337.     if(root && root.HC_PENDING)
  338.     {
  339.         for(i in root.HC_CHAIN)
  340.         {
  341.             node_Server_out_final( root.HC_COLL[i] );
  342.         }
  343.  
  344.         root.HC_CHAIN    = [];
  345.         root.HC_SELECTED = null;
  346.         root.HC_PENDING  = false;
  347.     }
  348. }
  349.  
  350. function node_Server_out_final( node )
  351. {
  352.     node.className = "Taxo-Block";
  353.  
  354.     var cell = node.HC_ATTACHFLYOUT;
  355.     if(cell && cell.style.display == "")
  356.     {
  357.         cell.style.display = "none";
  358.     }
  359. }
  360.